home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / NetInteger.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  4.0 KB  |  129 lines

  1. package symantec.itools.db.net;
  2.  
  3. import java.io.DataOutputStream;
  4. import java.io.IOException;
  5. import symjava.lang.Bignum;
  6. import symjava.sql.SQLException;
  7.  
  8. class NetInteger extends NumberField {
  9.    int _iVal;
  10.  
  11.    int getType() {
  12.       return 82;
  13.    }
  14.  
  15.    void readData(ServerObject data) throws SQLException, IOException, ErrorException {
  16.       this._iVal = ((NetData)data).getInt();
  17.    }
  18.  
  19.    void writeData(DataOutputStream os) throws IOException {
  20.       NetData data = new NetData(this._iVal);
  21.       data.write(os);
  22.    }
  23.  
  24.    public String getString() throws SQLException {
  25.       return ((Field)this).isNull() ? null : String.valueOf(this._iVal);
  26.    }
  27.  
  28.    public boolean getBoolean() throws SQLException {
  29.       if (((Field)this).isNull()) {
  30.          return false;
  31.       } else {
  32.          return this._iVal != 0;
  33.       }
  34.    }
  35.  
  36.    public byte getByte() throws SQLException {
  37.       return ((Field)this).isNull() ? 0 : (byte)this._iVal;
  38.    }
  39.  
  40.    public short getShort() throws SQLException {
  41.       return ((Field)this).isNull() ? 0 : (short)this._iVal;
  42.    }
  43.  
  44.    public int getInt() throws SQLException {
  45.       return ((Field)this).isNull() ? 0 : this._iVal;
  46.    }
  47.  
  48.    public long getLong() throws SQLException {
  49.       return ((Field)this).isNull() ? 0L : (long)this._iVal;
  50.    }
  51.  
  52.    public float getFloat() throws SQLException {
  53.       return ((Field)this).isNull() ? 0.0F : (float)this._iVal;
  54.    }
  55.  
  56.    public double getDouble() throws SQLException {
  57.       return ((Field)this).isNull() ? (double)0.0F : (double)this._iVal;
  58.    }
  59.  
  60.    public Bignum getBignum(int scale) throws SQLException {
  61.       return ((Field)this).isNull() ? null : new Bignum(this._iVal, scale);
  62.    }
  63.  
  64.    public void setBoolean(boolean x) throws SQLException {
  65.       if (x) {
  66.          this._iVal = 1;
  67.       } else {
  68.          this._iVal = 0;
  69.       }
  70.  
  71.       super._null = false;
  72.    }
  73.  
  74.    public void setByte(byte x) throws SQLException {
  75.       this._iVal = x;
  76.       super._null = false;
  77.    }
  78.  
  79.    public void setShort(short x) throws SQLException {
  80.       this._iVal = x;
  81.       super._null = false;
  82.    }
  83.  
  84.    public void setInt(int x) throws SQLException {
  85.       this._iVal = x;
  86.       super._null = false;
  87.    }
  88.  
  89.    public void setLong(long x) throws SQLException {
  90.       this._iVal = (int)x;
  91.       super._null = false;
  92.    }
  93.  
  94.    public void setFloat(float x) throws SQLException {
  95.       Float f = new Float(x);
  96.       this._iVal = f.intValue();
  97.       super._null = false;
  98.    }
  99.  
  100.    public void setDouble(double x) throws SQLException {
  101.       Double d = new Double(x);
  102.       this._iVal = d.intValue();
  103.       super._null = false;
  104.    }
  105.  
  106.    public void setBignum(Bignum x) throws SQLException {
  107.       this._iVal = x.intValue();
  108.       super._null = false;
  109.    }
  110.  
  111.    public void setString(String x) throws SQLException {
  112.       Integer i = new Integer(x);
  113.       this._iVal = i;
  114.       super._null = false;
  115.    }
  116.  
  117.    public int getSQLType() {
  118.       return 4;
  119.    }
  120.  
  121.    public Object getObject() throws SQLException {
  122.       return new Integer(this._iVal);
  123.    }
  124.  
  125.    public void setObject(Object obj) throws SQLException {
  126.       this.setInt((Integer)obj);
  127.    }
  128. }
  129.